package org.java.dao.DaoImpl;

import com.alibaba.druid.util.JdbcUtils;
import org.java.entity.Goods;
import org.java.util.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class GoodsDao {
    private JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtil.getDataSource());
    //加载全部数据
    public List<Goods> getList(int page,int rows) {
        //开始下标
        int startIndex = (page-1)*rows;
        String sql = "select * from goods limit ?,?";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Goods.class),startIndex,rows);
    }

    //查询数据总数
    public int getCount(){
        String sql="select count(*) from goods";
        return jdbcTemplate.queryForObject(sql,Integer.class);
    }
}
